package com.googlecode.cswish.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.googlecode.cswish.model.Code;

/**
 * Static data maintain
 * 
 * @author Jerry.Feng 2008-11-13
 */
@Service
public class CodeCategory {

	private Map<String, List<Code>> codeMap
		= new HashMap<String, List<Code>>();
	
	public CodeCategory() {
		reset();
	}
	
	public void reset() {
		{
			String category = "sex";
			
			List<Code> categories = new ArrayList<Code>();
			categories.add(new Code("1", getText("male", null)));
			categories.add(new Code("2", getText("female", null)));
			codeMap.put(category, categories);
		}
		
		{
			// more categories from DB or configuration files
		}
	}
	
	public Collection<Code> getCodes(String category, boolean containBlankItem) {
		List<Code> codes = codeMap.get(category);
		if (codes == null) {
			return null;
		}
		
		if (containBlankItem) {
			List<Code> codesWithBlankItem = new ArrayList<Code>(codes.size() + 1);
			codesWithBlankItem.add(new Code("", getText("select...", null)));
			codesWithBlankItem.addAll(codes);
			return codesWithBlankItem;
		} else {
			return codes;
		}
	}
	
	private String getText(String key, Locale locale) {
		return key;
	}
}
